function convertTimetoString() {
    jQuery('.converttimetostring').each(function() {
        var curDate = new Date();
        var CurTime = curDate.getTime();
        CurTime = CurTime / 1000;
        var subTime = jQuery(this).attr('data-timeUnix');
        var temp = Math.abs(CurTime - subTime);
        var hour = Math.floor(temp / 3600);
        var minture = Math.ceil((temp - hour * 3600) / 60);
        if (hour > 24) {
            var result = jQuery(this).attr('data-string');
            jQuery(this).text(result);
        } else if (hour > 0) {
            jQuery(this).text('Cách đây ' + hour + ' giờ');
        } else {
            jQuery(this).text('Cách đây ' + minture + ' phút');
        }
    });
}

/*run when click share button*/
jQuery('.fbshare').click(function() {
    FB.ui({
        method: 'feed',
        link: jQuery(this).attr('data-link'),
        name: jQuery(this).attr('data-name'),
        picture: jQuery(this).attr('data-picture'),
        description: jQuery(this).attr('data-description'),
        caption: jQuery(this).attr('data-caption'),
    }, function(response) {
    }
    );
});

/*display total count link share of facebook*/
function getTotalCountFB() {
    var url = '';
    var urlt = ''
    jQuery('.fbshare').each(function() {
        url += jQuery(this).attr('data-oglink') + "','";
        urlt += jQuery(this).attr('data-link') + "','";
    });
    jQuery.ajax({
        type: 'GET',
        url: "https://graph.facebook.com/fql?q=SELECT url, normalized_url, share_count, like_count, comment_count, total_count, commentsbox_count, comments_fbid, click_count FROM link_stat WHERE url IN('" + url + "')",
        datatype: 'Json',
        async: false,
        success: function(data) {
            jQuery('.fbshare').each(function() {
                var urlo = jQuery(this).attr('data-oglink');
                var obj = jQuery(this);
                jQuery.each(data.data, function(index, value) {
                    if (value.url == urlo) {
                        jQuery(obj).siblings('.fbshare_1').text(value.total_count);
                    }
                });
            });
        }
    });
    jQuery.ajax({
        type: 'GET',
        url: "https://graph.facebook.com/fql?q=SELECT url, normalized_url, share_count, like_count, comment_count, total_count, commentsbox_count, comments_fbid, click_count FROM link_stat WHERE url IN('" + urlt + "')",
        datatype: 'Json',
        async: false,
        success: function(data) {
            jQuery('.fb-comment-count').each(function() {
                var urlo = jQuery(this).attr('data-href');
                var obj = jQuery(this);
                jQuery.each(data.data, function(index, value) {
                    if (value.url == urlo) {
                        jQuery(obj).text(value.comment_count);
                    }
                });
            });
        }
    });

}

/**
 * Play WAV beeps easily in javascript!
 */
function jBeep(soundFile) {
    if (!soundFile)
        soundFile = "../images/icon/sound.mp3";

    var soundElem, bodyElem, isHTML5;

    isHTML5 = true;
    try {
        if (typeof document.createElement("audio").play == "undefined")
            isHTML5 = false;
    }
    catch (ex) {
        isHTML5 = false;
    }

    bodyElem = document.getElementsByTagName("body")[0];
    if (!bodyElem)
        bodyElem = document.getElementsByTagName("html")[0];

    soundElem = document.getElementById("jBeep");
    if (soundElem)
        bodyElem.removeChild(soundElem);
    if (isHTML5) {
        soundElem = document.createElement("audio");
        soundElem.setAttribute("id", "jBeep");
        soundElem.setAttribute("src", soundFile);
        soundElem.play();
    }
    else if (navigator.userAgent.toLowerCase().indexOf("msie") > -1) {

        soundElem = document.createElement("bgsound");
        soundElem.setAttribute("id", "jBeep");
        soundElem.setAttribute("loop", 1);
        soundElem.setAttribute("src", soundFile);
        bodyElem.appendChild(soundElem);
    }
    else {
        var paramElem;
        soundElem = document.createElement("object");
        soundElem.setAttribute("id", "jBeep");
        soundElem.setAttribute("type", "audio/wav");
        soundElem.setAttribute("style", "display:none;");
        soundElem.setAttribute("data", soundFile);
        paramElem = document.createElement("param");
        paramElem.setAttribute("name", "autostart");
        paramElem.setAttribute("value", "false");
        soundElem.appendChild(paramElem);
        bodyElem.appendChild(soundElem);
        try {
            soundElem.Play();
        }
        catch (ex) {
            soundElem.object.Play();
        }
    }

}